package com.crawler.waf.security.services.impl;

import org.springframework.security.core.Authentication;
import org.springframework.util.Assert;

import com.crawler.waf.security.authens.UserToken;
import com.crawler.waf.security.authentication.bearer.PreAuthenticatedBearerTokenAuthentication;
import com.crawler.waf.security.services.TokenService;
import com.crawler.waf.support.Constants;
import com.crawler.waf.utils.TokenManager;

public class UserCenterBearerTokenService implements TokenService {

    @Override
    public UserToken verifyToken(
            Authentication preAuthenticatedAuthentication) {
        Assert.notNull(preAuthenticatedAuthentication, "preAuthenticatedAuthentication");

        PreAuthenticatedBearerTokenAuthentication bearerTokenAuthentication = (PreAuthenticatedBearerTokenAuthentication) preAuthenticatedAuthentication;
        //校验并返回Token信
        return TokenManager.get(Constants.AUTHORIZATION_TYPE_BEARER, bearerTokenAuthentication.getBearerToken());
    }

}
